package com.rcpcompany.examples.flows.pages;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import com.rcpcompany.examples.flows.directors.FirstDirector;
import com.rcpcompany.ui.flows.AbstractFlowPage;
import com.rcpcompany.ui.flows.IFlowPage;

public class Page2Page extends AbstractFlowPage implements IFlowPage {

	private Text myCity;
	private Text myCountry;

	protected final FirstDirector myDirector;

	public Page2Page(FirstDirector d) {
		super("Page 2", null);
		myDirector = d;
	}

	@Override
	public void createControl(Composite parent) {
		Composite top = new Composite(parent, SWT.NONE);
		top.setLayout(new GridLayout(2, false));
		setControl(top);

		final Label cityLabel = new Label(top, SWT.NONE);
		final GridData gd_cityLabel = new GridData();
		cityLabel.setLayoutData(gd_cityLabel);
		cityLabel.setText("&City:");

		myCity = new Text(top, SWT.BORDER);
		myCity.addModifyListener(new ModifyListener() {
			public void modifyText(final ModifyEvent e) {
				updated();
			}
		});
		final GridData gd_firstName = new GridData(SWT.FILL, SWT.CENTER, true, false);
		myCity.setLayoutData(gd_firstName);

		final Label countryLabel = new Label(top, SWT.NONE);
		final GridData gd_countryLabel = new GridData();
		countryLabel.setLayoutData(gd_countryLabel);
		countryLabel.setText("C&ountry:");

		myCountry = new Text(top, SWT.BORDER);
		myCountry.addModifyListener(new ModifyListener() {
			public void modifyText(final ModifyEvent e) {
				updated();
			}
		});
		final GridData gd_lastName = new GridData(SWT.FILL, SWT.CENTER, true, false);
		myCountry.setLayoutData(gd_lastName);
	}

	protected void updated() {
		myDirector.setLocation(myCity.getText(), myCountry.getText());
		pageUpdated();
	}

	@Override
	public void refreshState() {
	}

	@Override
	public void saveState() {
	}

}
